@extends('admin.admin')

@section('content')
        <!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        商品管理
        <small>分类列表</small>
        <small>添加</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 控制面板</a></li>
        <li ><a href="#">商品管理</a></li>
        <li ><a href="/admin/category">分类列表</a></li>
        <li class="active">添加</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">

    <div class="row">
        <div class="col-xs-12">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">分类添加</h3>
                    <div class="pull-right">
                        <a href="{{Route('admin.category.index')}}" type="button" class="btn btn-block btn-success btn-xs"><i class="icon  glyphicon glyphicon glyphicon-menu-left"></i> 返回</a>
                    </div>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                {!! Form::model($category,['route'=>'admin.category.store','class'=>'form-horizontal'])  !!}
                    {!! Form::hidden('back_url',@$_SERVER['HTTP_REFERER']) !!}
                    <div class="box-body">

                        <?php $select = $category::getTreeList();?>

                        <?php

                            function myspace($n,$hasChild){
                                $enum = ['├','└'];
                                if ($hasChild){
                                    $space = $enum[0];
                                }else{
                                    $space = $enum[1];
                                }
                                $str = '';
                                for ($i=0;$i<=$n;$i++){
                                     $str.='&nbsp;&nbsp;';
                                }
                                return $str.$space;
                            }
                        $seletcItem[0] = '=请选择父节点=';

                        foreach ($select as $k=> $item){
                                $seletcItem [$item->cat_id]= myspace($item->deepth,$item->has_children).$item->cat_name;
                            }

                        ?>
                        <div class="form-group @if($errors->has('parent_id')) has-error   @endif">
                            <label for="exampleInputPassword1" class="col-sm-2 control-label">父级节点</label>
                            <div class='col-sm-3'>
                                {!! Form::select('parent_id',$seletcItem,old('parent_id'),['class'=>'form-control select2'])!!}
                                @if($errors->has('parent_id'))
                                    <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$errors->first('parent_id')}}</label>
                                @endif
                            </div>
                        </div>

                        <div class="form-group @if($errors->has('cat_name')) has-error   @endif">
                            <label for="exampleInputEmail1" class="col-sm-2 control-label">分类名称</label>
                            <div class='col-sm-3'>
                                {!! Form::text('cat_name',old('cat_name'),array('class'=>'form-control','placeholder'=>'请填写分类名称,如:商品分类'))!!}
                                @if($errors->has('cat_name'))
                                    <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$errors->first('cat_name')}}</label>
                                @endif
                            </div>
                        </div>



                        <div class="form-group @if($errors->has('cat_picture')) has-error   @endif">
                            <label class="col-sm-2 control-label" for="exampleInputPassword1">活动缩略图</label>

                            <div class="col-sm-2" style="width: 196px;">
                                <div class="box  box-default image-uploader">
                                    <style>
                                        .upload-btn{
                                            display: block; width:48px;height:30px;position: absolute;filter:alpha(opacity=0);-moz-opacity:0;-khtml-opacity: 0;opacity: 0;
                                        }
                                    </style>
                                    <!-- /.box-header -->
                                    <div class="box-body">

                                        <div style="width: 145px;height: 145px; display: block;">
                                            <img class="image" style="width: 145px;; padding: 1px;" width="145" height="145" src="@if (old('image_url')) {{old('image_url')}} @else http://placehold.it/525x240 @endif"/>
                                            <input type="hidden" class="image_url" name="image_url" value="{{old('image_url')}}">
                                        </div>
                                        <div class="message" style="width: 145px;height: 145px; position: absolute; padding: 5px; top:0; color: red; text-align: center; line-height: 145px;display: none;">

                                        </div>

                                        <div class="progress progress-xxs" style="position: absolute;width: 140px; left:13px; display: none;">
                                            <div class="progress-bar progress-bar-default " role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
                                            </div>
                                        </div>
                                    </div>
                                    <!-- /.box-body -->
                                    <div class="box-footer" style="position: relative">

                                        <button class="btn btn-sm btn-default btn-flat pull-left" type="button">上传</button>
                                        {!! Form::file('file',['class'=>'upload-btn fileupload','type'=>'file','data-url'=>'/admin/file_upload']) !!}
                                        {!! Form::hidden('cat_picture',old('cat_picture'),['class'=>'thumb']) !!}

                                        <button class="btn  btn-sm btn-danger btn-flat pull-right" type="button">删除</button>
                                    </div>
                                </div>
                                <!-- /.box -->
                            </div>

                            @if($errors->has('cat_picture'))
                                <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$errors->first('cat_picture')}}</label>
                            @endif
                        </div>

                        {{--<div style="" class="form-group @if($errors->has('tariff_percent')) has-error   @endif">--}}

                            {{--<label for="exampleInputPassword1" class="col-sm-2 control-label">关税百分比(%)</label>--}}
                            {{--<div class='col-sm-3'>--}}
                                {{--<div class="input-group">--}}
                                    {{--{!! Form::text('tariff_percent',old('tariff_percent'),array('class'=>'form-control','placeholder'=>'关税百分比'))!!}--}}
                                    {{--<span class="input-group-addon"><i class="fa ">%</i></span>--}}
                                {{--</div>--}}

                                {{--@if($errors->has('tariff_percent'))--}}
                                    {{--<label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$errors->first('tariff_percent')}}</label>--}}
                                {{--@endif--}}
                            {{--</div>--}}
                        {{--</div>--}}

                        <div style="" class="form-group @if($errors->has('excise_duty_percent')) has-error   @endif">

                            <label for="exampleInputPassword1" class="col-sm-2 control-label">消费税(%)</label>
                            <div class='col-sm-3'>
                                <div class="input-group">
                                    {!! Form::text('excise_duty_percent',old('excise_duty_percent'),array('class'=>'form-control','placeholder'=>'消费税'))!!}
                                    <span class="input-group-addon"><i class="fa ">%</i></span>
                                </div>

                                @if($errors->has('excise_duty_percent'))
                                    <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$errors->first('excise_duty_percent')}}</label>
                                @endif
                            </div>
                        </div>

                        <div style="" class="form-group @if($errors->has('value_added_tax_percent')) has-error   @endif">

                            <label for="exampleInputPassword1" class="col-sm-2 control-label">增值税(%)</label>
                            <div class='col-sm-3'>
                                <div class="input-group">
                                    {!! Form::text('value_added_tax_percent',old('value_added_tax_percent'),array('class'=>'form-control','placeholder'=>'增值税'))!!}
                                    <span class="input-group-addon"><i class="fa ">%</i></span>
                                </div>

                                @if($errors->has('value_added_tax_percent'))
                                    <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$errors->first('value_added_tax_percent')}}</label>

                                @endif
                            </div>
                         </div>

                         <div style="" class="form-group @if($errors->has('value_added_tax_percent')) has-error   @endif">

                            <label for="exampleInputPassword1" class="col-sm-2 control-label">增值税(%)</label>
                            <div class='col-sm-3'>
                                <div class="input-group">
                                    {!! Form::text('value_added_tax_percent',old('value_added_tax_percent'),array('class'=>'form-control','placeholder'=>'关税百分比'))!!}
                                    <span class="input-group-addon"><i class="fa ">%</i></span>
                                </div>

                                @if($errors->has('value_added_tax_percent'))
                                    <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$errors->first('value_added_tax_percent')}}</label>
                                @endif
                            </div>
                         </div>

                        <div class="form-group @if($errors->has('keywords')) has-error   @endif">
                            <label for="exampleInputEmail1" class="col-sm-2 control-label">分类关键词</label>
                            <div class='col-sm-3'>
                                {!! Form::text('keywords',old('keywords'),array('class'=>'form-control','placeholder'=>'请填写分类关键词,如:商品分类'))!!}
                                @if($errors->has('keywords'))
                                    <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$errors->first('keywords')}}</label>
                                @endif
                            </div>
                        </div>

                        <div class="form-group @if($errors->has('cat_desc')) has-error   @endif">
                            <label for="exampleInputEmail1" class="col-sm-2 control-label">分类描述</label>
                            <div class='col-sm-3'>
                                {!! Form::text('cat_desc',old('cat_desc'),array('class'=>'form-control','placeholder'=>'请填写分类描述,如:分类描述'))!!}
                                @if($errors->has('cat_desc'))
                                    <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$errors->first('cat_desc')}}</label>
                                @endif
                            </div>
                        </div>

                        <div class="form-group @if($errors->has('sort_order')) has-error   @endif">
                            <label for="exampleInputEmail1" class="col-sm-2 control-label">分类排序</label>
                            <div class='col-sm-3'>
                                {!! Form::text('sort_order',old('sort_order'),array('class'=>'form-control','placeholder'=>'请填写排序,如:100'))!!}
                                @if($errors->has('sort_order'))
                                    <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$errors->first('sort_order')}}</label>
                                @endif
                            </div>
                        </div>

                        <div class="form-group @if($errors->has('measure_unit')) has-error   @endif">
                            <label for="exampleInputEmail1" class="col-sm-2 control-label">计量单位</label>
                            <div class='col-sm-3'>
                                {!! Form::text('measure_unit',old('measure_unit'),array('class'=>'form-control','placeholder'=>'请填写分类计量单位,如:计量单位'))!!}
                                @if($errors->has('measure_unit'))
                                    <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$errors->first('measure_unit')}}</label>
                                @endif
                            </div>
                        </div>

                        <!-- <div class="form-group @if($errors->has('goods_type')) has-error   @endif">
                            <label for="exampleInputEmail1">分类搜索属性</label>
                            {!! Form::text('goods_type',old('goods_type'),array('class'=>'form-control','placeholder'=>'请填写分类搜索属性,如:分类搜索属性'))!!}
                            @if($errors->has('goods_type'))
                                <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$errors->first('goods_type')}}</label>
                            @endif
                        </div> -->
                    </div>
                    <!-- /.box-body -->

                    <div class="box-footer">
                        <div class="form-group no-padding">
                            {!! Form::hidden('_method', 'POST') !!}
                            <label class="col-sm-2 control-label">&nbsp;</label>
                            <div class="col-sm-3">
                                <button type="submit" class="btn btn-primary">保存</button>
                            </div>
                        </div>
                    </div>
                {!! Form::close()  !!}
            </div>
            <!-- /.box -->
        </div>
    </div>



</section>
<!-- /.content -->

<!-- Select2 -->
<script type="text/javascript" src="{{ asset("/components/AdminLTE/plugins/select2/select2.full.min.js") }}"></script>
<script src="{{ asset ("/components/blueimp-file-upload/js/vendor/jquery.ui.widget.js") }}"></script>
<script src="{{ asset ("/components/blueimp-file-upload/js/jquery.iframe-transport.js") }}"></script>
<script src="{{ asset ("/components/blueimp-file-upload/js/jquery.fileupload.js") }}"></script>
<script>
    $(function () {
        $('.image-uploader').each(function(k,imageUploader){
            var wrapper = $(imageUploader);//盒子
            var uploadBtn = wrapper.find('.fileupload');
            var imageFile = wrapper.find('.image');
            var progress = wrapper.find('.progress');
            var progressBar = progress.find('.progress-bar');
            var inputFile = wrapper.find('.thumb');
            var imageUrl = wrapper.find('.image_url');
            var message = wrapper.find('.message');

            var placeholder='';
            if(k==0){
                placeholder='http://placehold.it/525x240';
            }else if(k==1){
                placeholder='{{asset('/images/admin/img_placeholder1.png')}}';
            }else if(k==2){
                placeholder='{{asset('/images/admin/img_placeholder2.png')}}';
            }

            uploadBtn.click(function(){
                progressBar.css('width', 0 + '%');
                //imageFile.attr('src','http://placehold.it/525x240');
                inputFile.val('');
                message.hide();

            });
            wrapper.find('.btn-danger').click(function(){
                progressBar.css('width', 0 + '%');
                //imageFile.attr('src','http://placehold.it/525x240');
                imageFile.attr('src',placeholder);
                inputFile.val('');
                message.hide();

            });

            uploadBtn.fileupload({
                dataType: 'json',
                headers:{'X-CSRF-TOKEN':'{{csrf_token()}}'},
                add: function (e, data) {
                    data.submit();
                },
                progressall: function (e, data) {
                    progress.fadeIn();
                    var percent = parseInt(data.loaded / data.total * 100, 10);
                    if (progress==1){
                        progress.show()
                    }
                    progressBar.css('width', percent + '%');
                    setTimeout(function () {
                        progress.fadeOut();
                    }, 500);
                },
                done: function (e, data) {
                    imageFile.attr('src',data.result.url);
                    inputFile.val(data.result.id);
                    imageUrl.val(data.result.url);
                },
                complete:function(){
                }
            });
        });

        //修改色块
        $('.js-color').each(function(){
            var that=$(this),input=that.closest('.form-group').find('input');
            input.on('change input',function(){
                that.css('background-color','#'+$(this).val());
            });
        });
    });
</script>
<script>
    //Initialize Select2 Elements
    $(".select2").select2();
</script>

@endsection